/**********************************************************************************
Copyright (C), by AppleCai
Project                      : Study Kernel driver
Description                  : User Application for cdev
History                      :
CPU and Compiler             : AM335x,GCC
GenDate                      : 2020-10-29
OwnerBy                      : Apple Cai
**********************************************************************************/
#include "stdio.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "stdlib.h"
#include "string.h"
#include "poll.h"
#include "sys/select.h"
#include "sys/time.h"
#include "linux/ioctl.h"
#include "applepaper_cmd.h"
#include "signal.h"
static void signalio_handler(int signum)
{
	printf("received a signal(%d) from applepaper\n",signum);
}
int main(int argc, char *argv[])
{
	int fd;
	int ret = 0;
	int oflags = 0;
	char *filename;
	struct pollfd fds;
	fd_set readfds,writefds;
	struct timeval timeout;
	unsigned char data;

	if (argc != 2) {
		printf("Error Usage!\r\n");
		return -1;
	}

	filename = argv[1];
	fd = open(filename, O_RDWR, S_IRUSR|S_IWUSR);
	if (fd < 0) {
		printf("Can't open file %s\r\n", filename);
		return -1;
	}
	else{
		signal(SIGIO,signalio_handler);
		fcntl(fd,F_SETOWN,getpid());
		oflags = fcntl(fd,F_GETFL);
		fcntl(fd,F_SETFL,oflags|FASYNC);
		while(1){
			sleep(50);
		}
	}

	close(fd);
	return ret;
}
